package com.ylr.config.framework.controller.api;

import com.ylr.config.framework.service.MappingService;
import com.ylr.base.common.tool.Result;
import com.ylr.config.common.dto.mapping.SimpleMappingDto;
import com.ylr.config.framework.feign.YcMappingBaseClient;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-05-02 18:58:56
 * className: MappingWebController
 * version: 1.0
 * description:
 */
@Validated
@RestController
@RequestMapping("/api/mapping")
@AllArgsConstructor
public class MappingApiController implements YcMappingBaseClient {

    private static final Logger log = LoggerFactory.getLogger(MappingApiController.class);

    private final MappingService mappingService;

    /**
     * 获取键值对映射接口
     * @param key 键
     * @return 键值对映射数据
     */
    @GetMapping("/find")
    public Result<SimpleMappingDto> getMapping(@RequestParam("key") String key) {
        log.info("api => 开始获取键值对映射操作。key={}", key);

        SimpleMappingDto simpleMappingDto = mappingService.getSimpleMapping(key);

        log.info("api => 获取键值对映射操作结束。{}", simpleMappingDto);
        return Result.success(simpleMappingDto);
    }

}
